valid = true;

function check_name(){
	if(document.getElementById('name').value == '' || document.getElementById('name').value == 'Nome')
	{
		document.getElementById('no_name').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	else
		$('#no_name').fadeOut('slow');
};

function check_surname(){
	if(document.getElementById('surname').value == '' || document.getElementById('surname').value == 'Cognome')
	{
		document.getElementById('no_surname').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	else
		$('#no_surname').fadeOut('slow');
};

function check_mail(){
	mail = document.getElementById('mail').value;
	if(mail == '')
	{
		document.getElementById('no_mail').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	else
	{
		$('#no_mail').fadeOut('slow');
	}
	if(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+.([a-zA-Z])+([a-zA-Z])+/.test(mail))
	{
		$('#invalid_mail').fadeOut('slow');
	}
	else
	{
		document.getElementById('invalid_mail').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	for(i=0; i<mails.length; i++)
	{
		if(mail == mails[i])
		{
			document.getElementById('exist_mail').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
			valid = false;
			break;
		}
		else
		{
			$('#exist_mail').fadeOut('slow');
		}
	}
};

function check_mail2(){
	mail = document.getElementById('mail').value;
	if(mail == '')
	{
		document.getElementById('no_mail').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	else
	{
		$('#no_mail').fadeOut('slow');
	}
	if(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+.([a-zA-Z])+([a-zA-Z])+/.test(mail))
	{
		$('#invalid_mail').fadeOut('slow');
	}
	else
	{
		document.getElementById('invalid_mail').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	mail_correct = false;
	for(i=0; i<mails.length; i++)
	{
		if(mail == mails[i])
		{
			valid = true;
			mail_correct = true;
			break;
		}
		else
		{
			mail_correct = false;
			valid = false;
		}
	}
	if(mail_correct)
		$('#no_exist_mail').fadeOut('slow');
	else
		document.getElementById('no_exist_mail').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
};

function check_pass(){
	if(document.getElementById('pass').value == '')
	{
		document.getElementById('no_pass').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	else
		$('#no_pass').fadeOut('slow');
};

function check_pass2(){
	if(document.getElementById('pass2').value == '')
	{
		document.getElementById('no_pass2').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
		valid = false;
	}
	else
		$('#no_pass2').fadeOut('slow');
	
	pass1 = document.getElementById('pass').value;
	pass2 = document.getElementById('pass2').value;
	if(pass1 != pass2)
	{
		document.getElementById('diff_pass').setAttribute('style', 'margin-left:10px; padding:6px; display:inline; padding-left:45px;');
			valid = false;
	}
	else
		$('#diff_pass').fadeOut('slow');
};



function validate(){
valid = true;
check_name();
check_surname();
check_mail();
check_pass();
check_pass2();

if(document.getElementById('mail').value == 'Mail' || document.getElementById('pass').value == 'Password' || document.getElementById('pass2').value == 'Ripeti Password')
	valid = false;

if(valid)
	document.forms['req'].submit();

}

function validate_new_pass(){
valid = true;
check_mail2();

if(document.getElementById('mail').value == 'Mail')
	valid = false;

if(valid)
	document.forms['reset_pass'].submit();

}


